package com.qfjy.controller;

import com.qfjy.entity.po.MeetingPub;
import com.qfjy.service.MeetingPubService;
import com.qfjy.util.result.ResultCode;
import com.qfjy.util.result.ResultJson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

/**
 * @Classname MeetingPubController
 * @Author guoweixin
 * @Description TODO
 * @Date 2021/3/25 11:38
 * @Created by Administrator
 */
@RequestMapping("meetingPub")
@Controller
@Slf4j
public class MeetingPubController {

    @Autowired
    private MeetingPubService meetingPubService;

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("byPcode")    // rest ful  @PathVa..
    @ResponseBody
    public ResultJson selectByPcode(@RequestParam String pcode){
        MeetingPub meetingPub=meetingPubService.selectByPcode(pcode);

        if(meetingPub==null){
            return new ResultJson(null, ResultCode.NOT_DATA);
        }else{
            log.info("会议微服务被调用--》根据会议编号查询会议信息");

            /**
             * param1 url 请求的URL地址
             * param2 responseType 希望返回的类型.class
             * param3 占位符 最后一个参数是map,map的key为前面的占位符。map value为参数值
             * 可变长度的参数，一一来替换前面的占位符 name={name}形式，
             */
            // String url=http://localhost:8085/videoInfo/20201216002

           // String url="http://localhost:8085/videoInfo/{pcode}";
            String url="http://localhost:8085/videoInfo/"+meetingPub.getPcode();
            ResponseEntity<String> responseEntity= restTemplate.getForEntity(url,String.class);
             String result= responseEntity.getBody();
            meetingPub.setRemark(result);

            return  new ResultJson(meetingPub);
        }
    }
}
